package com.example.casper.jnuexperiment2025;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ShopItemActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_shop_item);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        Button okButton= findViewById(R.id.button_item_details_ok);
        okButton.setOnClickListener(button->{
            Intent intent = new Intent();
            EditText editTextName= findViewById(R.id.edittext_item_name);
            intent.putExtra("item name",editTextName.getText().toString());

            EditText editTextPrice = findViewById(R.id.edittext_item_price);
            intent.putExtra("item price",Double.parseDouble(editTextPrice.getText().toString()));

            intent.putExtra("item position",this.getIntent().getIntExtra("item position",0));
            this.setResult(Activity.RESULT_OK,intent);
            this.finish();
        });

        EditText editTextPrice = findViewById(R.id.edittext_item_price);
        editTextPrice.setText(String.format("%s", this.getIntent().getDoubleExtra("item price", 0)));
        EditText editTextName= findViewById(R.id.edittext_item_name);
        editTextName.setText(this.getIntent().getStringExtra("item name"));
    }
}